#include <stdio.h>

int main() {
    int n, m, arr[1000];
    
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    
    scanf("%d", &m);
    
    int found = 0;  
    while (1) {
        int index = -1;
        
        for (int i = 0; i < n; i++) {
            if (arr[i] == m) {
                index = i;
                break;
            }
        }
        
        if (index != -1) {
            found = 1;
            for (int i = index; i < n - 1; i++) {
                arr[i] = arr[i + 1];
            }
            n--;  

            for (int i = 0; i < n; i++) {
                printf("%d ", arr[i]);
            }
            printf("\n");
        } else {
            break;  
        }
    }

    if (!found) {
        for (int i = 0; i < n; i++) {
            printf("%d ", arr[i]);
        }
        printf("\n");
    }

    return 0;
}
